#include "RelOp.h"

void Project::Run(Pipe &inPipe, Pipe &outPipe, int *keepMe, int numAttsInput, int numAttsOutput){

    in = &inPipe;
    out = &outPipe;
    this->keepMe = keepMe;
    this->numAttsInput = numAttsInput;
    this->numAttsOutput = numAttsOutput;

    pthread_create(&thread, NULL, ProjectWorker, (void*)this);
}

void Project::WaitUntilDone(){
    pthread_join(thread, NULL);
}

void Project::Use_n_Pages(int n){
    nOfPages = n;
}

void Project::DoWork(){
    Record *temp;
    bool b = true;

    do{
        temp = new Record;
        if (b = in->Remove(temp)){
            temp->Project(keepMe, numAttsOutput, numAttsInput);
            out->Insert(temp);
        }
    }while(b);

    out->ShutDown();
}

void *ProjectWorker(void *param){
     Project project = *((Project*) param);
     project.DoWork();
}
